﻿function require() {
    if (!$("#Vacancy").val()) {
        alert("机柜数量未显示，请稍候！");
        return false;
    }
    return true;
}
$(function () {
    $("#OldPutServer").submit(function () {
        //alert(parseInt($("#UseNumber").val()));
        if (parseInt($("#UseNumber").val()) > parseInt($("#Vacancy").val())) {
            $("#U_error").html("U数不能大于剩余架数，请换一台服务器").css("color", "red");
            return false;
        }
        else {
            return true;
        }
    });

    $('#pageSize').on("change", function () {
        var name = $("input[name='name']").val();
        var assetClassId = $("input[name='assetClassId']").val();
        var companyId = $("input[name='companyId']").val();
        var code = $("input[name='code']").val();
        var sdt = $("input[name='sdt']").val();
        var edt = $("input[name='edt']").val();
        var size = $(this).val();
        location.href = "/assetes/Index?code=" + code + "&name=" + name + "&assetClassId=" + assetClassId + "&companyId=" + companyId + "&sdt=" + sdt + "&edt=" + edt + "&pageSize=" + size;
    });
    $("#checkBoxs").on("change", function () {
        if ($(this).val() > 0) {
            $("#sure_div").css({ "display": "block" });
            $(".c_Box").css({ "display": "block" });
            //$(".table th:last").css( "display", "none" );
            //$(".table tr").each(function(){$(this).children(":last").css({ "display": "none" })});
            if ($(this).val() == 1) {
                $(".c_Box").each(function () {
                    $(this).children().removeAttr("checked");
                    if ($(this).children().attr("data-IsStorage") != 1) {
                        $(this).children().attr("disabled", "");
                    }
                });
            }
            else {
                $(".c_Box").each(function () {
                    $(this).children().removeAttr("checked");
                    $(this).children().removeAttr("disabled");
                });
            }
        }
        else {
            //$(".table tr").each(function(){$(this).children(":last").css({ "display": "block" })});  
            $("#sure_div").css({ "display": "none" });
            $(".c_Box").css({ "display": "none" });
        }
    });
    $("#All_check").on("click", function () {
        if ($(this).prop("checked")) {
            $("input[name='checkbox']").not("[disabled]").prop("checked", "true");
        }
        else {
            $("input[name='checkbox']").removeAttr("checked");
        }
    });

    $("#sure_checkBoxs").on("click", function () {
        var len = $("td input:checked").length;
        if (len <= 0) {
            alert("请选择数据");
        }
        else {
            var str = "";
            $("td input:checked").each(function () {
                str = str + "," + $(this).attr("id");
            });
            if ($("#checkBoxs").val() == 1) {
                $.post("/Assetes/BatchPut", { ids: str }, function (result) {

                    location.reload();
                });
            }
            else {
                $.post("/Assetes/BatchDelete", { ids: str }, function () {
                    location.reload();
                });
            }
        }
    });


    //$("#CabinetId").on("change", function () {
    //    var id = $(this).val();
    //    $("#u_NO").load("/Common/part_PutAway?cabinetId=" + id);
    //});


    //if (re.test($("#serverPurposeId").val())) {
    //    var id = $("#serverPurposeId").val();
    //    $("#subPurpose").load("/Common/part_serverSubPurpose?purposeId=" + id);
    //}
    //$("#serverPurposeId").on("change", function () {
    //    var id = $("#serverPurposeId").val();
    //    $("#subPurpose").load("/Common/part_serverSubPurpose?purposeId=" + id);
    //});
    $("#Code").on("change", function () {
        if ($(this).val() != "") {
            var code = $(this).val();
            $("#use_NO").load("/Common/part_useNO?code=" + code);
        }
    });
    //$("#serverPurposeSubId").on("click", function () {
    //    alert(1);
    //    var s = $(this).val();
    //    if (s == 1) {
    //        $("#property").css({ "display": "block" });
    //        $("#Tproperty").css({ "display": "none" });
    //    }
    //    else if (s == 2) {
    //        $("#Tproperty").css({ "display": "block" });
    //        $("#property").css({ "display": "none" });
    //    }
    //    else {
    //        $("#property").css({ "display": "none" });
    //        $("#Tproperty").css({ "display": "none" });
    //    }
    //});
    $("#serverPurposeSubId").on("change", function () {
        //alert(2);
        var s = $(this).val();
        if (s == 1) {
            $("#property").css({ "display": "block" });
            $("#Tproperty").css({ "display": "none" });
        }
        else if (s == 2) {
            $("#Tproperty").css({ "display": "block" });
            $("#property").css({ "display": "none" });
        }
        else {
            $("#property").css({ "display": "none" });
            $("#Tproperty").css({ "display": "none" });
        }
    });
    $("#serverPurposeId").on("change", function () {
        //alert(3);
        var id = $("#serverPurposeId").val();
        var subId=$("#serverPurposeSubId").val();
        $("#subPurpose").load("/Common/part_serverSubPurpose?purposeId=" + id);
        if(id!=1)
        {
            $("#property").css({ "display": "none" });
            $("#Tproperty").css({ "display": "none" });
        }
        else {
           
                $("#property").css({ "display": "block" });
                $("#Tproperty").css({ "display": "none" });
          
        }
    });
});
function put_confirm(assetId) {
    var r = confirm("确定入库？")
    if (r == true) {
        layer.open({
            type: 1, //加上边框
            area: ['220px', '100px'], //宽高
            content: '正在入库，请稍后...'
        });
        setTimeout(function () {
            $.post("/Assetes/Put", { id: assetId }, function (result) {
                //var data=JSON.parse(result);
                //alert(data);
                //if(result==0)
                //{
                //    alert("入库成功");
                //}
                //else{
                //    alert("入库失败");
                //}
                location.reload();
            });
        }, 1000);
    }
}
function IpForm(id) {
    //var id = $(this).attr("date-id");
    var IpID = '#IPs_' + id;
    var Ip = "主IP：" + $(IpID).html();
    var subIp = "辅IP：" + $(IpID).attr("data-Ips").replace(/[,]/g, "<br/>");
    //alert(subIp);
    if (subIp.length > 4) {
        var x = $(IpID).offset().top;
        var y = $(IpID).offset().left;
        var width = $(IpID).width();
        var height = $(IpID).parent("tr").height();
        $("#layer").html(Ip + "<br>" + subIp);
        $("#layer").css({
            "position": "absolute",
            "display": "block",
            "background-color": "#f3f3f3",
            "z-index": 20000,
            "width": width,
            "min-height": height,
            "top": x,
            "left": y
        });
    }
};
